package com.zrrd.yt.weball.controller;

import com.zrrd.yt.common.result.Result;
import com.zrrd.yt.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @author HongyueYang
 */
@Controller
public class WebItemController {
    @Autowired
    private ItemFeignClient itemFeignClient;

    @GetMapping("/{skuId}.html")
    public String getItem(@PathVariable("skuId") Long skuId, Model model){
        //1.通过feign请求汇总服务获取数据
        Result<Map> result = itemFeignClient.getItem(skuId);
        //2.将数据存入到model对象中
        model.addAllAttributes(result.getData());
        //3.转发请求 跳转页面
        return "/item/index";
    }
}
